
<?php 
$sql4 = "SELECT `Total Housing Units`, `Vacant Housing Units`, `Housing Units for Seasonal, Recreational or Occasional Use`, `Homeowner Vacancy Rate`, `Rental Vacancy Rate`, `Occupied Housing Units_1`, `Owner-Occupied Housing Units`, `Renter Occupied Housing Units`, `Ave Household Size Owner-Occupied Units`, `Ave Household Size Renter-Occupied Units` FROM `ZipCode Profile1` as occupancy WHERE `ZCTA5` = $zipcode";
	
		
$result = mysql_query($sql4,$db);
$numrows = mysql_num_rows($result);
if ($result)
{
	$result_row = mysql_fetch_array($result,MYSQL_ASSOC);
	if($result_row)
	{
		$total_houses = $result_row['Total Housing Units'];
		$ocupied_houses = $result_row['Occupied Housing Units_1'];
		$vacant_houses = $result_row['Vacant Housing Units'];

		$owner_occupied = $result_row['Owner-Occupied Housing Units'];
		$renter_occupied = $result_row['Renter Occupied Housing Units'];
		
		$avg_hhold_size_owner_occ = $result_row['Ave Household Size Owner-Occupied Units'];
		$avg_hhold_size_renter_occ = $result_row['Ave Household Size Renter-Occupied Units'];

		
	}
}

if($total_houses != 0 && $ocupied_houses != 0)
{

$occupied_housing_percet = number_format((100*$ocupied_houses)/$total_houses,2);

$vacant_houses_percet = number_format((100*$vacant_houses)/$total_houses,2);

$owner_occupied_percet = number_format((100*$owner_occupied)/$ocupied_houses,2);

$renter_occupied_percet = number_format((100*$renter_occupied)/$ocupied_houses,2);


echo "<Table width=250px cellspacing='-1' bordar=0>";
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td >Total Housing Units: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$total_houses;
	  echo "</td>";
	  echo "</tr>";


	  echo "<tr style='width:100%;font-size:12px'>";
	  echo "<td>Vacant Housing Units: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$vacant_houses." (".$vacant_houses_percet."%)";
	  echo "</td>";
	  echo "</tr>";

      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td>Occupied Housing Units: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$occupied_houses." (".$occupied_housing_percet."%)";
	  echo "</td>";
	  echo "</tr>";

	  echo "<tr style='width:100%;font-size:12px'>";
	  echo "<td>Owner Occupied Homes: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$owner_occupied." (".$owner_occupied_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td>Renter Occupied Homes: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$renter_occupied." (".$renter_occupied_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  
	  echo "<tr style='width:100%;font-size:12px'>";
	  echo "<td >Avg Household Size Owner-Occupied : ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$avg_hhold_size_owner_occ;
	  echo "</td>";
	  echo "</tr>";
	  
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td >Avg Household Size Renter-Occupied : ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$avg_hhold_size_renter_occ;
	  echo "</td>";
	  echo "</tr>";


echo "</Table>";
}
else
{
if($numrows == 0)
{
$nodata_msg = "Data is not available.  Please make sure the City, State and Zipcode Information is correct.";
}
else
{
$nodata_msg = "Data is not available for this Zipcode.";
}

echo "<Table width=250px cellspacing='-1' bordar=0>";
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td align='right' nowrap='nowrap'>".$nodata_msg;
	  echo "</td>";

	  echo "</Table>";


}

?>